package com.csgc.camera.biz.other.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast

import com.csgc.camera.base.BaseBindingActivity
import com.csgc.camera.bean.MaskEditInfo
import com.csgc.camera.constants.MaskConfig

import com.csgc.camera.events.CustomMaskEvent
import com.csgc.camera.util.clickWithTrigger
import com.cysd.spsyxj.R
import com.cysd.spsyxj.databinding.ActivityAddCustomMaskBinding

import com.drake.channel.sendEvent
import com.gyf.immersionbar.ktx.immersionBar
import com.hjq.toast.ToastUtils
import com.hlyj.http.ad.NewGroMoreFeedAdManager
import com.hnyyac.ad.mds.IAdView
import com.hnyyac.ad.mds.IAdViewListener
import com.hnyyac.ad.mds.manager.AdManager
import com.hnyyac.ad.mds.manager.AdManager.AdLoadListener
import com.hnyyac.ad.mds.utils.BaseAdConstants

class AddCustomMaskActivity:BaseBindingActivity<ActivityAddCustomMaskBinding>(ActivityAddCustomMaskBinding::inflate),IAdViewListener {

    companion object{
        fun launch(context: Context){
            context.startActivity(Intent(context,AddCustomMaskActivity::class.java))
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        immersionBar {
            //界面在状态栏底部true   界面在状态栏下面沉浸式盖着界面false
            fitsSystemWindows(true)
            //白色状态栏，黑色字体
            statusBarColor(R.color.white)
            statusBarDarkFont(true)
        }
        initEvents()
        //广告插入
        val newGromoreFeedAd: NewGroMoreFeedAdManager = NewGroMoreFeedAdManager(this, BaseAdConstants.FEEDAD_Id, binding?.frameContent, 66)
        newGromoreFeedAd.loadAd()
        showDoubleChaPin()
    }


    private fun initEvents(){
        binding.ivBack.clickWithTrigger {
            finish()
        }

        binding.stvSave.clickWithTrigger {
            val title = binding.etTitle.text.toString().trim()
            val content = binding.etContent.text.toString().trim()
            if (title.isEmpty()){
                ToastUtils.show("标题不能为空")
                return@clickWithTrigger
            }
            if (content.isEmpty()){
                ToastUtils.show("内容不能为空")
                return@clickWithTrigger
            }
            val item = MaskEditInfo(title = title, content = content, canHide = true, isOpen = true, isCustom = true)
            MaskConfig.customMaskInfo.add(item)
            sendEvent(CustomMaskEvent(title,content))
            finish()
        }
    }
    //统一双插屏无需加位置
    fun showDoubleChaPin(){
        AdManager.loadTwoChapinSimultaneously(
            this,
            666,
            this,
            object : AdLoadListener {
                override fun onAdLoadFailed(ad: IAdView?) {

                }
            })
    }

    override fun onTrigger(adView: IAdView) {

    }

    override fun onAdShow(adView: IAdView) {

    }

    override fun onAdClick(adView: IAdView) {

    }

    override fun onAdClose(adView: IAdView) {

    }

    override fun onError(msg: String) {

    }

    override fun onLoadError(adView: IAdView) {

    }

    override fun onSuccess(adView: IAdView) {

    }

    override fun onLoad(adView: IAdView) {

    }

    override fun onSkipped() {

    }

    override fun onNoAd() {

    }

    override fun onTimeOut() {

    }
}